﻿using System.Collections.Generic;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Marvin.Tests.CsvTrainingDataParserTests
{
    [TestClass]
    public class ReadsFourDimensionalDataCorrectly
    {
        private const int FourDimensionalData = 4;

        private static readonly List<string> ValidCsv = new List<string>
            {
                "1.0, 2.0, 3.0, 4.0, 0.0",
                "1.0  ,     2.0, 3.0, 4.0, 0.0",
                "2.1,3.2,1.2,23.12,0.0"
            };

        private static readonly double[][] ExpectedData = new []
            {
                new [] {1.0,2.0,3.0, 4.0 },
                new [] {1.0,2.0,3.0, 4.0 },
                new [] {2.1,3.2,1.2,23.12}
            };

        private CsvTrainingDataParser _parser; 

        [TestInitialize]
        public void CreateAParserForFourFeatures()
        {
            _parser = new CsvTrainingDataParser(FourDimensionalData); 
        }

        [TestMethod]
        public void WhenDefiningAFourDimensionalCsvFileAFourDimensionalTrainingSetIsCreated()
        {
            ITrainingSet<double> trainingSet = _parser.Parse(ValidCsv);
            Assert.AreEqual(FourDimensionalData, trainingSet.Dimensions);
        }

        [TestMethod]
        public void WhenReadingAValidThreeLineCsvDataFileTheResultingTrainingSetHasASizeOfThree()
        {
            ITrainingSet<double> trainingSet = _parser.Parse(ValidCsv);
            Assert.AreEqual(ValidCsv.Count, trainingSet.NumberOfTrainingExamples);
        }

        [TestMethod]
        public void ParsedDataMatchesOurTestData()
        {
            ITrainingSet<double> trainingSet = _parser.Parse(ValidCsv);
            bool isEqual = TestHelpers.DeepSequenceEquals(ExpectedData, trainingSet.GetX());
            Assert.IsTrue( isEqual );
        }
    }
}
